<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class SystemStoreStaff extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 查询字段模式
     *
     *  nickname => '%field%' 模糊查询
     *  created_at= (ge)field
     * @var array
     */
    public $searchableModels = [
        'product_name' => '%field%',
    ];


    public $searchable = [
        'user_id',
        'store_id',
        'staff_name',
        'phone',
        'verify_status',
        'status',
       'created_at'
    ];

    public $fillable = [
        'user_id',
        'store_id',
        'avatar',
        'staff_name',
        'phone',
    ];

    public $sortable = [
        'user_id',
        'store_id',
    ];

    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 店员所属用户
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id','id');
    }

    /**
     * 店员所属商店
     */
    public function systemStore()
    {
        return $this->belongsTo(SystemStore::class, 'store_id','id');
    }

    /**
     * 核销关联的订单
     */
    public  function order()
{
    return $this->hasMany(Order::class,'clerk_id','id');

}
/**
 * 核销3相关的门店
 */
    public function store(){
        return $this->belongsTo(SystemStore::class,'store_id','id');
    }

}
